<?php

namespace app\admin\controller\hf;

use app\common\controller\Backend;
use think\Db;

/**
 * 话费订单
 *
 * @icon fa fa-circle-o
 */
class Qdorder extends Backend
{

    /**
     * Qdorder模型对象
     * @var \app\admin\model\hf\Qdorder
     */
    protected $model = null;
    protected $dataLimit = true;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\hf\Qdorder;
        $this->view->assign("statussList", $this->model->getStatussList());
        $this->view->assign("yysList", $this->model->getYysList());
        $this->view->assign("cztypeList", $this->model->getCztypeList());
        $this->view->assign("fromList", $this->model->getFromList());
    }



    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model

                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);

            foreach ($list as $row) {
                $row->visible(['orderno', 't1', 'date', 't0', 'account', 'statuss', 'createtime', 'api_rst', 'mz', 'user_id', 'province', 'city', 'yys', 'cztype', 'price', 'charge_amount', 'remark', 'image', 'title', 'update_time', 'from']);
            }

            $d = $list->items();
            foreach ($d as $key => $value) {
                $t1 = time();
                if ($value['update_time'] > 0) {
                    // $d[$key]['t1'] = date('Y-m-d', $value['updatetime']) . '<br>' . date('H:i:s', $value['updatetime']);
                    $d[$key]['t1'] = date('Y-m-d H:i:s', $value['update_time']);
                }
                //状态:1=未付款,2=充值中,3=成功,4=失败退款,5=部分成功
                if ($value['statuss'] == 3) {
                    $t1 = $value['update_time'];
                }
                $seconds = $t1 - $value['createtime'];
                $hours = intval($seconds / 3600);
                $date = $hours . "时" . gmdate('i分s秒', $seconds);
                if ($value['statuss'] == 1 || $value['statuss'] == 4) {
                    $date = "无";
                }
                //$date = date('H时i分s秒', $t1 - $value['createtime']);
                $d[$key]['date'] = $date;

                if ($value['createtime'] > 0) {
                    // $d[$key]['t0'] = date('Y-m-d', $value['createtime']) . '<br>' . date('H:i:s', $value['createtime']);
                    $d[$key]['t0'] = date('Y-m-d H:i:s', $value['createtime']);
                }
            }
            $result = array("total" => $list->total(), "rows" => $d);

            return json($result);
        }
        return $this->view->fetch();
    }
    /**
     * 设置
     */
    public  function set()
    {
        $kf_url = $this->request->request('kf_url');

        $admin = db::table('fa_admin')->where('id', $this->auth->id)->find();
        if ($this->request->isPost()) {


            db::table('fa_admin')->where('id', $this->auth->id)->update(['kf_url' => $kf_url]);
            return $this->success('修改成功');
        }

        //平台 A B h5
        //平台 A h5
        $this->assign('kf_url', $admin['kf_url']);
        return $this->view->fetch();
    }
}
